import java.util.Arrays;
import java.util.Random;

/**
 * @author : zzr
 * @description :
 * @date :
 */
public class Test {

    /**
     * 创建顺序数组
     * @param array
     */
    public static void orderArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }

    /**
     * 创建一个逆序数组
     * @param array
     */
    public static void notOrderArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length - i;
        }
    }

    /**
     * 创建随机顺序的数组
     * @param array
     */
    public static void notOrderArrayRandom(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }

    public static void testInsertSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);

        long startTime = System.currentTimeMillis();
        Sort.insertSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序耗时：" + (endTime - startTime));
    }
    public static void testShellSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);

        long startTime = System.currentTimeMillis();
        Sort.shellSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序耗时：" + (endTime - startTime));
    }

    public static void testSelectSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);

        long startTime = System.currentTimeMillis();
        Sort.selectSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序耗时：" + (endTime - startTime));
    }

    public static void testHeapSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);

        long startTime = System.currentTimeMillis();
        Sort.heapSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序耗时：" + (endTime - startTime));
    }

    public static void testQuickSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);

        long startTime = System.currentTimeMillis();
        Sort.quickSort1(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序排序耗时：" + (endTime - startTime));
    }
    public static void testMergeSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);

        long startTime = System.currentTimeMillis();
        Sort.mergeSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序排序耗时：" + (endTime - startTime));
    }

    public static void main1(String[] args) {
        int[] array = new int[10_0000];
//        orderArray(array);
//        testQuickSort(array);
//        notOrderArray(array);
//        testQuickSort(array);
        notOrderArrayRandom(array);
        testShellSort(array);
        testQuickSort(array);
        testMergeSort(array);
    }

    public static void main(String[] args) {
        int[] array = {7, 14, 23, 2, 7, 10};
        Sort.countSort(array);
        System.out.println(Arrays.toString(array));
    }
}
